home *** CD-ROM | disk | FTP | other *** search
/ PC World 2008 September / PCWorld_2008-09_cd.bin / v cisle / sadanastroju / delicious_bookmarks-2.0.64-fx.xpi / chrome / deliciousBookmarks.jar / content / jumpAutoComplete.xml < prev    next >
Encoding:
Extensible Markup Language  |  2008-06-19  |  32.1 KB  |  904 lines

  1. <?xml version="1.0"?>
  2. <bindings xmlns="http://www.mozilla.org/xbl"
  3.         xmlns:html="http://www.w3.org/1999/xhtml"
  4.         xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  5.         xmlns:xbl="http://www.mozilla.org/xbl">
  6.         
  7.         <binding id="jumpAutoComplete">
  8.               <resources>
  9.         <script src="chrome://ybookmarks/content/ybookmarksUtils.js" type="application/x-javascript" />
  10.       </resources>
  11.               
  12.         <handlers>
  13.         <handler event="focus" phase="capturing">
  14.           <![CDATA[
  15.             if (!this.hasAttribute('focused')) {
  16.               this.setAttribute('focused','true');
  17.             }
  18.           ]]>
  19.         </handler>
  20.         
  21.         <handler event="blur" phase="capturing">
  22.           <![CDATA[
  23.                   this.removeAttribute('focused');
  24.                     this.hideTagSuggestions();
  25. //                      this.hideBookmarkSuggestions();
  26.  
  27.           ]]>
  28.         </handler>
  29.     
  30.             <handler event="keypress">
  31.                 <![CDATA[
  32.               switch(event.keyCode) {
  33.            case event.DOM_VK_DOWN:
  34.            case event.DOM_VK_UP:
  35.              event.preventDefault();
  36.              break;
  37.            case event.DOM_VK_ESCAPE:  //esc
  38.              if (this._areSuggestionsVisible()) {
  39.                event.preventDefault();         
  40.              }
  41.              break;
  42.            case event.DOM_VK_RETURN:  //enter
  43.              if (this.isSuggestionSelected()) {
  44.                event.preventDefault();         
  45.              }      
  46.              break;
  47.            case event.DOM_VK_TAB:
  48.              if (this._areSuggestionsVisible()) {
  49.                event.preventDefault();         
  50.              }
  51.              break;
  52.            default: 
  53.              this._lastEditTags = event.target.value; 
  54.          }
  55.              ]]>
  56.             </handler>
  57.         
  58.             <handler event="keyup">
  59.                 <![CDATA[
  60.                 switch (event.keyCode) {
  61.           case event.DOM_VK_DOWN:
  62.           case event.DOM_VK_UP:
  63.             event.preventDefault();
  64.             break;
  65.           case event.DOM_VK_ESCAPE:  //esc
  66.             if (this._areSuggestionsVisible()) {
  67.                         this.hideTagSuggestions();
  68.               event.preventDefault();
  69.             }
  70.             
  71.             if(this._areBookmarkSuggestionsVisible()) {
  72.                 this.hideBookmarkSuggestions();
  73.                 event.preventDefault();
  74.             }
  75.             break;
  76.           case event.DOM_VK_RETURN: //enter
  77.             if (this.isSuggestionSelected()) {
  78.               this.completeTag();
  79.               event.preventDefault();         
  80.             }
  81.             
  82.             if(this.isBookmarkSuggestionSelected()) {
  83.                 this.openBookmark();
  84.                 event.preventDefault();
  85.             }      
  86.             break;
  87.                 case event.DOM_VK_TAB:
  88.                     if (this._areSuggestionsVisible()) {
  89.                         if (this._tagSuggestionsPicked < 0) {
  90.                             this.selectTagSuggestion(0);
  91.                         }
  92.                       this.completeTag();
  93.               event.preventDefault();
  94.                     }
  95.                     break;
  96.           case event.DOM_VK_END:
  97.           case event.DOM_VK_HOME:
  98.           case event.DOM_VK_RIGHT:
  99.           case event.DOM_VK_LEFT:
  100.           case event.DOM_VK_SPACE:
  101.             this.hideTagSuggestions();
  102.             this.hideBookmarkSuggestions();
  103.             break;
  104.           default:
  105.             this.updateTagSuggestions(event.target);
  106.         }
  107.                 ]]>
  108.             </handler>
  109.             <handler event="keydown">
  110.                 <![CDATA[
  111.                 if (this._areSuggestionsVisible()) {
  112.            switch(event.keyCode) {
  113.              case event.DOM_VK_DOWN:
  114.                this.selectTagSuggestion((this._tagSuggestionsPicked + 1) % this._tagSuggestionsLength);
  115.                this.scrollTagSuggestions();
  116.                event.preventDefault();
  117.                break;
  118.              case event.DOM_VK_UP:
  119.                this.selectTagSuggestion((this._tagSuggestionsPicked == 0 || this._tagSuggestionsPicked == -1) ? this._tagSuggestionsLength - 1 : this._tagSuggestionsPicked - 1);
  120.                this.scrollTagSuggestions();
  121.                event.preventDefault();
  122.                break;
  123.            }
  124.          }
  125.  
  126.         if (this._areBookmarkSuggestionsVisible()) {
  127.            switch(event.keyCode) {
  128.              case event.DOM_VK_DOWN:
  129.                this.selectBookmarkSuggestion((this._bookmarkSuggestionsPicked + 1) % this._bookmarkSuggestionsLength);
  130.                this.scrollBookmarkSuggestions();
  131.                event.preventDefault();
  132.                break;
  133.  
  134.           case event.DOM_VK_RETURN: //enter
  135.             if(this.isBookmarkSuggestionSelected()) {
  136.                 this.openBookmark();
  137.                 event.preventDefault();
  138.             }      
  139.             break;
  140.  
  141.              case event.DOM_VK_UP:
  142.                this.selectBookmarkSuggestion((this._bookmarkSuggestionsPicked == 0 || this._bookmarkSuggestionsPicked == -1) ? this._bookmarkSuggestionsLength - 1 : this._bookmarkSuggestionsPicked - 1);
  143.                this.scrollBookmarkSuggestions();
  144.                event.preventDefault();
  145.                break;
  146.            }
  147.          }
  148.  
  149.          ]]>
  150.             </handler>
  151.             
  152.       </handlers>
  153.         <implementation>
  154.         <field name="_stringBundle" />
  155.               <field name="_tagInputBox" />
  156.       <field name="_lastEditTags" />
  157.       <field name="_currentTagText" />
  158.       <field name="_currentTagIndex">0</field>
  159.       <field name="_currentBookmarkIndex">0</field>
  160.       <field name="_tagsTextboxWidth">0</field>
  161.       <field name="_tagSuggestionsPicked">-1</field>
  162.       <field name="_tagSuggestionsLength">0</field>
  163.       <field name="_bookmarkSuggestionsPicked">-1</field>
  164.       <field name="_bookmarkSuggestionsLength">0</field>
  165.       <field name="_tagInputTimeout">250</field>
  166.       <field name="_tagInputTimer" />
  167.       <field name="_lastTagSuggestion" />
  168.       <field name="_lastBookmarkSuggestion" />
  169.       <field name="_suggestionsPopupVisible">false</field>
  170.       <field name="_bookmarkSuggestionsPopupVisible">false</field>
  171.       <field name="_bookmarkTimer" />
  172.       <field name="_bookmarkSuggestions" />
  173.  
  174.             <property name="areSuggestionsVisible" onget="return this._areSuggestionsVisible();" />
  175.             
  176.             <property name="value">
  177.                 <setter>
  178.             <![CDATA[
  179.                     this._getTagTextBox().value = val;
  180.                     ]]>
  181.                 </setter>
  182.                 <getter>
  183.             <![CDATA[
  184.                         var input = this._getTagTextBox();
  185.                         if (!input.value) { 
  186.                             input.value= ""; 
  187.                         }
  188.                         return input.value;
  189.                     ]]>
  190.                 </getter>
  191.             </property>
  192.         <constructor>
  193.         <![CDATA[
  194.           try {
  195.                     this._tagInputBox = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-tags");
  196.                  
  197.                     //window.addEventListener("click", this.onClickListener, false); // cmyang: 2006-12-19 do we need this?
  198.                     
  199.                     this._stringBundle = document.getAnonymousElementByAttribute(this, "anonid", "ybJumpStrings");
  200.                     
  201.                     if (!this.getAttribute("popupmaxheight")) {
  202.                         this.setAttribute("popupmaxheight", 100);                        
  203.                     }
  204.                     
  205.             } catch (e) { yDebug.print("constructor: " +e, YB_LOG_MESSAGE);}
  206.                     ]]>
  207.       </constructor>
  208.                     <method name="focus">
  209.         <body><![CDATA[
  210.                     this._getTagTextBox().focus();
  211.                 ]]></body>
  212.             </method>
  213.  
  214.             <method name="_getTagSuggestions">
  215.         <body><![CDATA[
  216.                     return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-suggestions");
  217.                 ]]></body>
  218.             </method>
  219.             
  220.             <method name="_getBookmarkSuggestions">
  221.         <body><![CDATA[
  222.                     return document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestions");
  223.                 ]]></body>
  224.             </method>
  225.  
  226.             <method name="_getTagTextBox">
  227.         <body><![CDATA[
  228.                     return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-tags");
  229.                 ]]></body>
  230.             </method>
  231.     
  232.             <method name="_getTagSuggestionsPopup">
  233.         <body><![CDATA[
  234.                     return document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-popup");
  235.                 ]]></body>
  236.             </method>
  237.     
  238.             <method name="_getBookmarkSuggestionsPopup">
  239.         <body><![CDATA[
  240.                     return document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestionPopup");
  241.                 ]]></body>
  242.             </method>
  243.  
  244.             <method name="_areSuggestionsVisible">
  245.         <body><![CDATA[
  246.                     return this._suggestionsPopupVisible;
  247.                 ]]></body>
  248.             </method>
  249.  
  250.             <method name="_areBookmarkSuggestionsVisible">
  251.         <body><![CDATA[
  252.                     return this._bookmarkSuggestionsPopupVisible;
  253.                 ]]></body>
  254.             </method>
  255.         
  256.             <method name="_getPopupMaxHeight">
  257.         <body><![CDATA[
  258.                     return this.getAttribute("popupmaxheight");
  259.                 ]]></body>
  260.             </method>
  261.         
  262.       <method name="isSuggestionSelected">
  263.         <body><![CDATA[
  264.           if (this._areSuggestionsVisible() && this._tagSuggestionsPicked >= 0) {
  265.             return true;
  266.           }
  267.           return false;
  268.         ]]></body>
  269.       </method>
  270.  
  271.       <method name="isBookmarkSuggestionSelected">
  272.         <body><![CDATA[
  273.           if (this._areBookmarkSuggestionsVisible() && this._bookmarkSuggestionsPicked >= 0) {
  274.             return true;
  275.           }
  276.           return false;
  277.         ]]></body>
  278.       </method>
  279.  
  280.       <method name="scrollTagSuggestions">
  281.         <body><![CDATA[
  282.           var suggestionBox = this._getTagSuggestions();
  283.           var row = suggestionBox.firstChild;
  284.     
  285.           var scrollTo = row.boxObject.height * this._tagSuggestionsPicked;
  286.           var scrollBoxObj = suggestionBox.boxObject.
  287.           QueryInterface(Components.interfaces.nsIScrollBoxObject);
  288.           var x = {}, y = {};
  289.     
  290.           scrollBoxObj.getPosition(x, y);    
  291.           scrollBoxObj.scrollTo(x.value, scrollTo);
  292.         ]]></body>
  293.       </method>
  294.  
  295.       <method name="scrollBookmarkSuggestions">
  296.         <body><![CDATA[
  297.         try {
  298.           var suggestionBox = this._getBookmarkSuggestions();
  299.  
  300.          var item = suggestionBox.getItemAtIndex(this._bookmarkSuggestionsPicked);
  301.          suggestionBox.ensureElementIsVisible(item);
  302.         } catch(e) {
  303.             //alert(e);
  304.         }
  305.         ]]></body>
  306.       </method>
  307.  
  308.         <method name="clearTagSelection">
  309.         <body><![CDATA[
  310.             try {
  311.             for(var i=0; i < suggestionBox.childNodes.length; i++) {
  312.                 suggestionBox.childNodes[i].removeAttribute("highlight");
  313.             }
  314.             } catch(e) { }
  315.         ]]></body>
  316.         </method>
  317.         <method name="clearBookmarkSelection">
  318.         <body><![CDATA[
  319.             try {
  320.             var suggestionBox = this._getBookmarkSuggestions();
  321.             for(var i=0; i < suggestionBox.childNodes.length; i++) {
  322.                 suggestionBox.childNodes[i].removeAttribute("highlight");
  323.             }
  324.             } catch(e) { }
  325.         ]]></body>
  326.         </method>
  327.  
  328.       <method name="selectTagSuggestion">
  329.         <parameter name="index" />
  330.         <body><![CDATA[
  331.         
  332.           if(this._bookmarkTimer) {
  333.               clearTimeout(this._bookmarkTimer);
  334.           }
  335.           
  336.           this.clearTagSelection();
  337.           
  338.           if (this._tagSuggestionsLength == 1) index = 0;
  339.           var suggestionBox = this._getTagSuggestions();
  340.           if (this._tagSuggestionsPicked > -1 && suggestionBox.childNodes[this._tagSuggestionsPicked])
  341.             suggestionBox.childNodes[this._tagSuggestionsPicked].removeAttribute("highlight");
  342.           this._tagSuggestionsPicked = index;
  343.       
  344.          if (this._tagSuggestionsPicked > -1)
  345.            suggestionBox.childNodes[this._tagSuggestionsPicked].setAttribute("highlight", "true");
  346.          
  347.          var func = function(me, tag) {
  348.             me.updateBookmarkSuggestions(tag);
  349.              me.showBookmarkSuggestions();
  350.          }
  351.          
  352.          var prefService =
  353.                 Components.classes["@mozilla.org/preferences-service;1"]
  354.                           .getService(Components.interfaces.nsIPrefBranch);
  355.          var timeout = prefService.getIntPref("extensions.ybookmarks@yahoo.tagSuggestionWait.interval");
  356.  
  357.          if(suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag")) {
  358.              this._bookmarkTimer = setTimeout(func, timeout, this, suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag"));
  359.          }
  360.         ]]></body>
  361.       </method>
  362.  
  363.       <method name="selectBookmarkSuggestion">
  364.         <parameter name="index" />
  365.         <body><![CDATA[
  366.           var suggestionBox = this._getBookmarkSuggestions();
  367.           
  368.           this.clearBookmarkSelection();
  369.           
  370.           if (this._bookmarkSuggestionsLength == 1) index = 0;
  371.  
  372.           if (this._bookmarkSuggestionsPicked > -1 && suggestionBox.childNodes[this._bookmarkSuggestionsPicked])
  373.             suggestionBox.childNodes[this._bookmarkSuggestionsPicked].removeAttribute("highlight");
  374.           this._bookmarkSuggestionsPicked = index;
  375.       
  376.          if (this._bookmarkSuggestionsPicked > -1)
  377.            suggestionBox.childNodes[this._bookmarkSuggestionsPicked].setAttribute("highlight", "true");
  378.         ]]></body>
  379.       </method>
  380.  
  381.             <method name="updateTagSuggestions">
  382.         <parameter name="target" />
  383.         <body><![CDATA[
  384.           try {
  385.                     if (this._tagInputTimer) {
  386.             clearTimeout(this._tagInputTimer);
  387.           }
  388.  
  389.           if(!this.getCurrentTag() || !this._currentTagIndex) { 
  390.             this.hideTagSuggestions(); 
  391.                         return; 
  392.           }
  393.             
  394.             if(this._areBookmarkSuggestionsVisible()) {
  395.                 this.hideBookmarkSuggestions();
  396.             }
  397.                     var func = function(target, me) { 
  398.             me._updateTagSuggestions( target.value );
  399.           };
  400.  
  401.           this._tagInputTimer = setTimeout(func, this._tagInputTimeout, target, this);
  402.                     } catch (e) { yDebug.print(e);}
  403.         ]]></body>
  404.       </method>
  405.         <method name="_updateTagSuggestions">
  406.         <parameter name="input" />
  407.         <body><![CDATA[
  408.                     try {
  409.           if (!this.getCurrentTag() || !this._currentTagIndex) { 
  410.             this.hideTagSuggestions(); 
  411.                         return; 
  412.           }
  413.  
  414.           var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";       
  415.        
  416.           var tags = input.split(/\s */);
  417.        
  418.           var currentInput = tags[this._currentTagIndex];
  419.           if (currentInput && 
  420.               this._lastTagSuggestionLength > 0 && 
  421.               currentInput.length >= this._lastTagSuggestionLength && 
  422.               currentInput.indexOf(this._lastTagSuggestion) == 0) {
  423.  
  424.             var suggestionBox = this._getTagSuggestions();
  425.             var element = suggestionBox.firstChild;
  426.             var nElement, tag;
  427.             while (element) {
  428.               nElement = element;
  429.               element = element.nextSibling;
  430.               tag = nElement.getAttribute("tag");
  431.               if (tag.indexOf(currentInput) == -1) {
  432.                 suggestionBox.removeChild(nElement);
  433.               }
  434.             }
  435.  
  436.             this._lastTagSuggestion = currentInput;
  437.           }
  438.           else {
  439.                   
  440.             var localStore = ( Components.classes[ "@mozilla.org/ybookmarks-store-service;1" ].
  441.                                       getService( Components.interfaces.nsIYBookmarksStoreService ) );
  442.  
  443.             var suggestions = localStore.getTagSuggestions(currentInput, true);
  444.  
  445.             var suggestionBox = this._getTagSuggestions();
  446.             var suggestion, tag, count;
  447.             var row, text;
  448.        
  449.             //remove everything in type down
  450.             while (suggestionBox.firstChild) {
  451.               suggestionBox.removeChild(suggestionBox.firstChild);
  452.             }
  453.  
  454.             //add stuff in
  455.             outer: for (var i = 0; i < suggestions.length; i++) {
  456.                 if(i == 15) break;
  457.                 
  458.                    suggestion = suggestions.queryElementAt(i, Components.interfaces.nsIWritablePropertyBag);
  459.                   tag = suggestion.getProperty("tag");
  460.                 count = suggestion.getProperty("count");
  461.         
  462.                 //row = document.createElementNS(gXUL_NS, "row");
  463.                 /**
  464.                  * Create text heading
  465.                  */
  466.                 if(i == 0) {
  467.                     headText = document.getAnonymousElementByAttribute(this, "anonid", "ybTagSuggestHeading");
  468.                     headText.setAttribute("class", "suggestionHeading");
  469.                     headText.setAttribute("value", this._stringBundle.getString("extensions.ybookmarks.ybJump.suggestionHeading"));
  470.                 }
  471.                 
  472.                 text = document.createElementNS(gXUL_NS, "text");
  473.                 text.setAttribute("color", ((i%2)? "white" : "grey"));
  474.                 text.setAttribute("class", "suggestion-tag");
  475.                 text.setAttribute("value", tag + " (" + count + ")");
  476.                 text.setAttribute("tag", tag);
  477.                 text.addEventListener("click", this.completeTag, false);
  478.                 text.addEventListener("mouseover", function() { this.setAttribute("highlight", "true"); }, false);
  479.                 text.addEventListener("mouseout", function() { this.removeAttribute("highlight"); }, false);
  480.  
  481.                 suggestionBox.appendChild(text);
  482.               }
  483.         
  484.                  if (currentInput) {
  485.                         this._lastTagSuggestion = currentInput;
  486.                 } else {
  487.                     this._lastTagSuggestion = "";
  488.                         }
  489.          }
  490.          
  491.           this._tagSuggestionsLength = suggestionBox.childNodes.length;
  492.           
  493.       
  494.           if (suggestionBox.childNodes.length > 0) {       
  495.             this.showTagSuggestions();
  496.           } else {
  497.             this.hideTagSuggestions();    
  498.           }
  499. } catch(e) { yDebug.print("_updateTagSuggestions(): " + e, YB_LOG_MESSAGE);}
  500.         ]]></body>
  501.       </method>
  502.       
  503.       <method name="showTagSuggestions">
  504.         <body><![CDATA[
  505.           try {
  506.                     var suggestionBox = this._getTagSuggestions();       
  507.                  var suggestionPopup = this._getTagSuggestionsPopup();       
  508.                     var inputBox = this._getTagTextBox();
  509.         
  510.               suggestionBox.style.overflow = "-moz-scrollbars-none";
  511.           if(ybookmarksUtils.getFFMajorVersion() > 2) {
  512.               var posY = this._tagInputBox.boxObject.screenY + this._tagInputBox.boxObject.height - 3; 
  513.           }
  514.           else {
  515.               var posY = document.documentElement.boxObject.y + this._tagInputBox.boxObject.y + this._tagInputBox.boxObject.height - 3; 
  516.           }
  517.                            
  518.           //set the position X of the suggestion box
  519.           var pos = 0;
  520.           var tags = this.getUserInputTags("array");
  521.      
  522.           for(var i = 0; i < this._currentTagIndex; i++) {
  523.             pos += tags[i].length + 1;
  524.           }     
  525.           var text = this.getUserInputTags("string").substr(0, pos);
  526.  
  527.           var invisibleTags = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-invisible-tags");
  528.           var invisibleBox = document.getAnonymousElementByAttribute(this, "anonid", "ybTagAutoComplete-invisible-box");
  529.           invisibleTags.value = text;
  530.           invisibleBox.hidden = false;
  531.           var invisibleTagsWidth = invisibleTags.boxObject.width;
  532.           invisibleBox.hidden = true;
  533.           invisibleTags.value = "";
  534.          
  535.           var offsetX = 2;
  536.           if ((invisibleTagsWidth + suggestionBox.boxObject.width) > this._tagInputBox.boxObject.width) {
  537.             offsetX += this._tagInputBox.boxObject.width - suggestionBox.boxObject.width;
  538.           } else {
  539.             offsetX += invisibleTagsWidth;
  540.           }
  541.          
  542.           if(ybookmarksUtils.getFFMajorVersion() > 2) {
  543.             var posX = this._tagInputBox.boxObject.screenX + offsetX;
  544.           }
  545.           else {
  546.             var posX = this._tagInputBox.boxObject.x + offsetX;
  547.           }
  548.  
  549.             if(this._areBookmarkSuggestionsVisible()) {
  550.                 this.hideBookmarkSuggestions();
  551.             }
  552.                     document.popupNode = document.documentElement; // needed for some bug
  553.                     //reduce the height of scrollbox
  554.                     suggestionBox.setAttribute("maxheight", this._getPopupMaxHeight() - 70);
  555.                     suggestionPopup.showPopup(document.documentElement, posX, posY, "popup");
  556.                     this._suggestionsPopupVisible = true;
  557.                     
  558.                     //make first matching tag selected by default
  559.                     this.selectTagSuggestion(0);
  560.                     
  561.                     //figure out if overloaded
  562.                     if (suggestionBox.boxObject.height >= this._getPopupMaxHeight() - 70) {
  563.                         suggestionBox.style.overflow = "-moz-scrollbars-vertical";
  564.                         yDebug.print("added bars");
  565.                     }
  566.                     
  567.                     } catch (e) { yDebug.print("Exception from jump autocomplete: "+e, YB_LOG_MESSAGE);}
  568.         ]]></body>
  569.       </method>
  570.  
  571.       <method name="hideTagSuggestions">
  572.         <body><![CDATA[
  573.     
  574.                  var suggestionPopup = this._getTagSuggestionsPopup();       
  575.                     suggestionPopup.hidePopup();
  576.                     this._suggestionsPopupVisible = false;
  577.             this._tagSuggestionsPicked = -1;
  578.           this._tagSuggestionsLength = 0;
  579.      
  580.           if (this._tagInputTimer) {
  581.             clearTimeout(this._tagInputTimer);
  582.             this._tagInputTimer = null;
  583.           }  
  584.         ]]></body>
  585.       </method>
  586.  
  587.       <method name="getElementById">
  588.         <parameter name="format" />
  589.         <body><![CDATA[
  590.           var tags = this._tagInputBox.value;
  591.           if (format == "string") {
  592.             return tags;
  593.           }
  594.           else {
  595.             var tagArray = tags.split(/\s */);
  596.             return tagArray;
  597.           }  
  598.         ]]></body>
  599.       </method>
  600.  
  601.       <method name="setUserInputTags">
  602.         <parameter name="inputTagArray" />
  603.         <body><![CDATA[
  604.           this._tagInputBox.value = inputTagArray.join(" ") + " ";
  605.         ]]></body>
  606.       </method>
  607.  
  608.       <method name="completeTag">
  609.         <parameter name="event" />
  610.         <body><![CDATA[
  611.         try {
  612.                     var boundElt;
  613.                   var selectedTag = "";
  614.  
  615.           if (event) {
  616.                        selectedTag = event.target.getAttribute("tag");
  617.                          boundElt = event.target.parentNode.parentNode.parentNode.parentNode;    
  618.                     } else {
  619.             var suggestionBox = this._getTagSuggestions();
  620.             selectedTag = suggestionBox.childNodes[this._tagSuggestionsPicked].getAttribute("tag");
  621.                       boundElt = this; 
  622.             }
  623.                     
  624.                 var inputTagArray = boundElt.getUserInputTags("array");
  625.      
  626.           if (boundElt._currentTagIndex) {
  627.             var curTag = inputTagArray[ boundElt._currentTagIndex ];
  628.             var plusIndex = curTag.lastIndexOf( '+' );
  629.             if( plusIndex > -1 ) {    
  630.               // we need to add the tag at the end of existing string
  631.               selectedTag = curTag.substr( 0, plusIndex + 1 ) + selectedTag; 
  632.             }
  633.             inputTagArray[ boundElt._currentTagIndex ] = selectedTag;   
  634.           }
  635.            
  636.           boundElt.setUserInputTags( inputTagArray );
  637.           boundElt.hideTagSuggestions();
  638.        } catch(e) { }
  639.         ]]></body>
  640.       </method>
  641.  
  642.       <method name="getCurrentTag">
  643.         <parameter name="" />
  644.         <body><![CDATA[
  645.           var tags = this.getUserInputTags("string");
  646.           if (tags == this._lastEditTags) return true;
  647.           if (tags == "") return false;
  648.      
  649.           this._currentTagText = "";
  650.           this._currentTagIndex = 0;
  651.           
  652.           var tagArray = tags.toLowerCase().split(/\s */);
  653.           var oldArray = this._lastEditTags.toLowerCase().split(/\s */);
  654.           var matched = false;
  655.           var currentTags = new Array();
  656.           for (t in tagArray) {
  657.             for (o in oldArray) {
  658.               if (typeof oldArray[o] == "undefined") {
  659.                 yDebug.print("remove the " + o + ":" + oldArray[o]);
  660.                 oldArray.splice(o,1); 
  661.                 break;
  662.               }
  663.               if (tagArray[t] == oldArray[o]) { 
  664.                 matched = true; 
  665.                 oldArray.splice(o,1); 
  666.                 break; 
  667.               }
  668.             }
  669.             if (!matched) {
  670.               currentTags[currentTags.length] = t;
  671.             }  
  672.             matched = false;          
  673.           }
  674.      
  675.           // more than one word changed... abort
  676.           if(currentTags.length > 1) { 
  677.             this.hideTagSuggestions(); 
  678.             return false; 
  679.           }
  680.      
  681.           this._currentTagText = tagArray[currentTags[0]];
  682.           this._currentTagIndex = currentTags[0];
  683.           
  684.           return true;
  685.         ]]></body>
  686.       </method>
  687.  
  688.       <method name="onClickListener">
  689.         <parameter name="event" />
  690.         <body><![CDATA[
  691.     try {
  692.                    var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";       
  693.             if (event.target.nodeName != "jumpautocomplete") {
  694.                          var tacs = document.getElementsByTagNameNS(gXUL_NS, "jumpautocomplete");
  695.             for (var i=0; i < tacs.length; i++) {
  696.                             var tac = tacs.item(i);
  697.                             if (tac._areSuggestionsVisible()) {
  698.                   tac.hideTagSuggestions();
  699.                             }
  700.             }
  701.           }} catch(e) { yDebug.print("onClickListener(): " + e);}
  702.         ]]></body>
  703.       </method>
  704.  
  705.       <method name="getUserInputTags">
  706.         <parameter name="format" />
  707.         <body><![CDATA[
  708.           var tags = this._tagInputBox.value;
  709.           if (format == "string") {
  710.             return tags;
  711.           }
  712.           else {
  713.             var tagArray = tags.split(/\s */);
  714.             return tagArray;
  715.           }  
  716.         ]]></body>
  717.       </method>
  718.       
  719.       <method name="updateBookmarkSuggestions">
  720.       <parameter name="tag"/>
  721.       <body>
  722.       <![CDATA[
  723.       try {
  724.         
  725.         if(!this._currentTagText) return;
  726.         
  727.           var gXUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
  728.           var row, title, url;
  729.           
  730.           var suggestionBox = this._getBookmarkSuggestions();
  731.           
  732.           //update list box
  733.         var localStore = ( Components.classes[ "@mozilla.org/ybookmarks-store-service;1" ].
  734.                                   getService( Components.interfaces.nsIYBookmarksStoreService ) );
  735.  
  736.           this._bookmarkSuggestions = localStore.getBookmarks(tag, {});
  737.  
  738.           //remove everything in type down
  739.         while (suggestionBox.firstChild) {
  740.           suggestionBox.removeChild(suggestionBox.firstChild);
  741.         }
  742.             
  743.         for(var i=0; i < this._bookmarkSuggestions.length; i++) {
  744.                /**
  745.              * Create text heading
  746.              */
  747.             if(i == 0) {
  748.                 headText = document.getAnonymousElementByAttribute(this, "anonid", "ybBookmarkSuggestHeading");
  749.                 headText.setAttribute("class", "suggestionHeading");
  750.                 headText.setAttribute("value", this._stringBundle.getFormattedString("extensions.ybookmarks.ybJump.bookmarkSuggestionHeading", [tag]));
  751.             }
  752.             
  753.             var maxlength = 30;
  754.             row = document.createElementNS(gXUL_NS, "richlistitem");
  755.             var vbox = document.createElementNS(gXUL_NS, "vbox");
  756.             title = document.createElementNS(gXUL_NS, "text");
  757.             title.setAttribute("value", (this._bookmarkSuggestions[i].name.length > maxlength) ? this._bookmarkSuggestions[i].name.substr(0, maxlength) + "..." : this._bookmarkSuggestions[i].name);
  758.             title.setAttribute("class", "suggestion-tag-title");
  759.             
  760.             url = document.createElementNS(gXUL_NS, "text");
  761.             url.setAttribute("value", (this._bookmarkSuggestions[i].url.length > maxlength) ? this._bookmarkSuggestions[i].url.substr(0, maxlength) + "..." : this._bookmarkSuggestions[i].url);
  762.  
  763.  
  764.             row.setAttribute("color", ((i%2)? "white" : "grey"));
  765.             row.setAttribute("class", "suggestion-tag");
  766.             row.setAttribute("url", this._bookmarkSuggestions[i].url);
  767.             row.addEventListener("mousedown", this.selectBookmark, false);
  768.             row.addEventListener("mouseover", function() { this.setAttribute("highlight", "true"); }, false);
  769.             row.addEventListener("mouseout", function() { this.removeAttribute("highlight"); }, false);
  770.             
  771.             vbox.setAttribute("minwidth", 210);
  772.             
  773.             vbox.appendChild(title);
  774.             vbox.appendChild(url);
  775.             row.appendChild(vbox);
  776.  
  777.             suggestionBox.appendChild(row);
  778.           }
  779.  
  780.         this._bookmarkSuggestionsLength = suggestionBox.childNodes.length;
  781.       } catch (e) {  }
  782.       ]]>
  783.       </body>
  784.       </method>
  785.       <method name="showBookmarkSuggestions">
  786.       <body><![CDATA[
  787.          try {
  788.             
  789.             if(!this._currentTagText) return;
  790.             
  791.              this.completeTag();
  792.              this.hideTagSuggestions();
  793.              
  794.             var suggestionBox = this._getBookmarkSuggestions();       
  795.             var suggestionPopup = this._getBookmarkSuggestionsPopup();       
  796.             var inputBox = this._getTagTextBox();
  797.  
  798.             if(ybookmarksUtils.getFFMajorVersion() > 2) {
  799.                    var posY = this._tagInputBox.boxObject.screenY + this._tagInputBox.boxObject.height - 3; 
  800.             }
  801.             else {
  802.                    var posY = document.documentElement.boxObject.y + this._tagInputBox.boxObject.y + this._tagInputBox.boxObject.height - 3; 
  803.             }
  804.                            
  805.             //set the position X of the suggestion box
  806.             var offsetX = 2;
  807.             
  808.             if(ybookmarksUtils.getFFMajorVersion() > 2) {
  809.               var posX = this._tagInputBox.boxObject.screenX + offsetX;
  810.             }
  811.             else {
  812.               var posX = this._tagInputBox.boxObject.x + offsetX;
  813.             }
  814.             
  815.             this._bookmarkSuggestionsPopupVisible = true;
  816.             document.popupNode = document.documentElement; // needed for some bug
  817.             //reduce the height of scrollbox
  818.             suggestionBox.setAttribute("maxheight", this._getPopupMaxHeight() - 70);
  819.             suggestionPopup.showPopup(document.documentElement, posX, posY, "popup");
  820.             
  821.         } catch (e) {  }    
  822.       ]]></body>
  823.       </method>
  824.  
  825.       <method name="openBookmark">
  826.       <body><![CDATA[
  827.           var suggestionBox = this._getBookmarkSuggestions();
  828.         
  829.         if(this._bookmarkSuggestionsPicked > -1 && suggestionBox.childNodes[this._bookmarkSuggestionsPicked] && this._bookmarkSuggestions[this._bookmarkSuggestionsPicked]) {
  830.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  831.                        .getService(Components.interfaces.nsIWindowMediator);
  832.             var mainWindow = wm.getMostRecentWindow("navigator:browser");
  833.             mainWindow.getBrowser().selectedTab = mainWindow.getBrowser().addTab(this._bookmarkSuggestions[this._bookmarkSuggestionsPicked].url);
  834.         }
  835.         
  836.         this.hideBookmarkSuggestions();
  837.         window.close();
  838.       ]]></body>
  839.       </method>
  840.  
  841.       <method name="selectBookmark">
  842.       <parameter name="event"/>
  843.       <body><![CDATA[
  844.       try {
  845.          if(event.target.tagName == "text") {
  846.              var row = event.target.parentNode.parentNode;
  847.          }
  848.          else if(event.target.tagName == "vbox") {
  849.              var row = event.target.parentNode;
  850.          }
  851.          else if(event.target.tagName == "richlistitem") {
  852.              var row = event.target;
  853.          }
  854.          
  855.         var url = row.getAttribute("url");
  856.  
  857.  
  858.          var bundleElm = row.parentNode.parentNode.parentNode.parentNode;
  859.  
  860.         if(url) {
  861.             var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  862.                           .getService(Components.interfaces.nsIWindowMediator);
  863.             var mainWindow = wm.getMostRecentWindow("navigator:browser");
  864.             mainWindow.getBrowser().selectedTab = mainWindow.getBrowser().addTab(url);
  865.         }
  866.  
  867.         bundleElm.hideBookmarkSuggestions();
  868.         window.close();
  869.     } catch(e) {  }
  870.       ]]></body>
  871.       </method>
  872.  
  873.       
  874.       <method name="hideBookmarkSuggestions">
  875.       <body><![CDATA[
  876.         this._bookmarkSuggestionsPopupVisible = false;
  877.           var suggestionPopup = this._getBookmarkSuggestionsPopup();       
  878.         suggestionPopup.hidePopup();
  879.       ]]></body>
  880.       </method>
  881.         </implementation>
  882.         <content>
  883.         <xul:stringbundleset>
  884.     <xul:stringbundle id="ybJumpStrings" anonid="ybJumpStrings" src="chrome://ybookmarks/locale/ybJump.properties"/>
  885. </xul:stringbundleset>
  886.       <xul:popupset>
  887.                 <xul:popup anonid="ybTagAutoComplete-popup" ignorekeys="true" xbl:inherits="maxheight=popupmaxheight">
  888.                      <xul:label anonid="ybTagSuggestHeading" value="" maxheight="20" minwidth="250"/>
  889.                      <xul:scrollbox anonid="ybTagAutoComplete-suggestions" orient="vertical" maxheight="10"/>                
  890.                 </xul:popup>
  891.                 <xul:popup anonid="ybBookmarkSuggestionPopup" ignorekeys="true" xbl:inherits="maxheight=popupmaxheight">
  892.                 <xul:label anonid="ybBookmarkSuggestHeading" value="" maxheight="20" minwidth="250"/>
  893.                 <xul:richlistbox anonid="ybBookmarkSuggestions" class="bookmarkSuggestionsList">
  894.                 </xul:richlistbox>
  895.                 </xul:popup>
  896.             </xul:popupset>
  897.             <xul:textbox anonid="ybTagAutoComplete-tags" xbl:inherits="onfocus,onblur,tabindex,cols,rows,flex,value,accesskey"/>
  898.       <xul:hbox anonid="ybTagAutoComplete-invisible-box" hidden="true">
  899.         <xul:label anonid="ybTagAutoComplete-invisible-tags"/>
  900.       </xul:hbox>                  
  901.         
  902.         </content>
  903.         </binding>
  904. </bindings>